/*=============================================================================
*
*   Copyright (C) 2020 All rights reserved.
*
*   Filename:		debugger.hpp
*
*   Author: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Date: 2020-02-09 03:40
*
*   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Last modified:	2020-03-03 15:54
*
*   Description:
*
=============================================================================*/
#ifndef GEOXFEM_LOG_H
#define GEOXFEM_LOG_H

#include <assert.h>
#include <string>

#define GEOXFEM_ASSERT(check) assert(check)

#ifndef NDEBUG
#define GEOXFEM_DEBUG_INFO() GEOXFEM_LOG_SEV(detail)
#else
#define GEOXFEM_DEBUG_INFO()
#endif

#ifndef NDEBUG
#define GEOXFEM_THROW(check, msg) \
  do {                            \
    if(!(check))                  \
      throw msg;                  \
  } while(false)
#else
#define GEOXFEM_THROW(check, msg)
#endif

#define GEOXFEM_NOT_IMPLEMENTED()                                  \
  do {                                                             \
    std::string s =                                                \
      std::string("\n\n***\n")                                     \
      + "***  "                                                    \
        "--------------------------------------------------------" \
        "-------------"                                            \
        "----\n"                                                   \
      + "***  Error:   Unable to excute function \"" + __func__    \
      + "\". It has not been implemented.\n"                       \
      + "***  Where:   This error was encountered inside "         \
      + geoxfem::log::path_to_filename(__FILE__)                   \
      + "@ : " + std::to_string(__LINE__) + ".\n"                  \
      + "***  "                                                    \
        "--------------------------------------------------------" \
        "-------------"                                            \
        "----\n"                                                   \
      + "***\n\n";                                                 \
    throw std::runtime_error(s);                                   \
  } while(false)

#define COMBINE1(X, Y) X##Y  // helper macro
#define COMBINE(X, Y) COMBINE1(X, Y)
#define TEMP_VAR COMBINE(var, __LINE__)

namespace geoxfem {
namespace log {
// Convert file path to only the filename
inline std::string path_to_filename(std::string path) {
  return path.substr(path.find_last_of("/\\") + 1);
}
}  // namespace log
}  // namespace geoxfem

#endif  /// _GEOXFEM_DEBUG_MACRO_H
